package com.xhwl.data.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.dto.cent.sdata.FloorDTO;
import com.xhwl.common.enums.OrganizationTypeEnum;
import com.xhwl.common.pojo.cent.sdata.Floor;
import com.xhwl.common.query.cent.sdata.FloorQuery;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: luyi
 * @Description:
 * @Date: Create in 16:51 2021/1/21
 */
@Repository
public interface IFloorDao extends BaseMapper<Floor> {

    Page<Floor> page(Page page, @Param("floorQuery") FloorQuery floorQuery);

    List<Floor> list(@Param("floorQuery") FloorQuery floorQuery);

    /**
     * 检查编码是否唯一
     *
     * @param dto
     * @param orgType
     * @return
     */
    @Select("select ifnull(count(id),0) from `cent_sdata`.`sdata_organization` " +
            "where `is_deleted` = 0 and `code` = #{dto.code} " +
            "and `type` = #{orgType} and `project_id` = #{dto.projectId}")
    Integer checkUniqueCode(@Param("dto") FloorDTO dto, @Param("orgType") OrganizationTypeEnum orgType);

    /**
     * 获取当前id
     *
     * @return
     */
    @Select("select max(id) + 1 currentId from `cent_sdata`.`sdata_floor`")
    Integer getCurrentId();
}
